<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>H+ 后台主题UI框架 - 数据表格</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">

    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>基本
                        <small>分类，查找</small>
                    </h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <select class="form-control input-sm" id="age" name="age">
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </div>
                        <div class="col-md-10">
                            <div class="input-group">
                                <input class="input-sm form-control" placeholder="姓名(可模糊匹配)" type="text" id="name"/>
                                <span class="input-group-btn">
                                        <button onclick="query()" class="btn btn-sm btn-primary"
                                                type="button"> 搜索</button> </span>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed m-t-sm m-b-sm"></div>
                    <table class="table table-striped table-bordered table-hove dataTables-example">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <th>年龄</th>
                            <th>姓名</th>
                            <th>手机</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                            <th>姓名</th>
                            <th>年龄</th>
                            <th>姓名</th>
                            <th>手机</th>
                        </tr>
                        </tfoot>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>


<script src="/js/plugins/jeditable/jquery.jeditable.js"></script>

<!-- Data Tables -->
<script src="/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/js/plugins/dataTables/dataTables.bootstrap.js"></script>

<!-- 自定义js -->
<script src="/js/content.js?v=1.0.0"></script>


<!-- Page-Level Scripts -->
<script>

    // 3个参数的名字可以随便命名,但必须是3个参数,少一个都不行
    function retrieveData(sSource, aoData, fnCallback) {
        //赋值参数
        aoData.name = $('#name').val();
        aoData.age = $('#age').val();

        console.log(JSON.stringify(aoData))
        $.ajax({
            url: sSource,//这个就是请求地址对应sAjaxSource
            data: aoData,//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数
            type: 'post',
            dataType: 'json',
            async: false,
            success: function (result) {
                fnCallback(result);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的
            },
            error: function (msg) {
                alert(msg);
            }
        });
    }


    //查询表格
    var table;
    function query() {
        table.api().ajax.reload(null, false); // 刷新表格数据，分页信息不会重置
    }

    //表格初始化
    $(document).ready(function () {
        table = $('.dataTables-example').dataTable({
            bFilter: false,    //去掉搜索框
//            bLengthChange: false,   //去掉每页显示多少条数据方法
            "sAjaxSource": "/demo/datas",//这个是请求的地址
            "fnServerData": retrieveData, // 获取数据的处理函数
            "bServerSide": true, //客户端处理分页
            "dom": '<"top"i>rt<"bottom"flp><"clear">',
            "language": {
                "info": ""
            },
            "columns": [
                {"data": "name"},
                {"data": "age"},
                {"data": "sex"},
                {"data": "phone"}
            ]
        });
    });
</script>

</body>

</html>
